function! LastSearchCount() abort
    let result = searchcount(#{recompute: 0})
    if empty(result)
        return ''
    endif
    if result.incomplete ==# 1     " timed out
        return printf(' /%s [?/??]', @/)
    elseif result.incomplete ==# 2 " max count exceeded
        if result.total > result.maxcount &&
                    \  result.current > result.maxcount
            return printf(' /%s [>%d/>%d]', @/,
                        \		    result.current, result.total)
        elseif result.total > result.maxcount
            return printf(' /%s [%d/>%d]', @/,
                        \		    result.current, result.total)
        endif
    endif
    return printf(' /%s [%d/%d]', @/,
                \		result.current, result.total)
endfunction
let &statusline=" %f %m %(%h%w%r%) %q%=%{v:hlsearch ? LastSearchCount() : \"\"} [%{&fileencoding}]%y %(%p%% %l/%L:%c%V%)  "

autocmd CursorMoved,CursorMovedI *
            \ let s:searchcount_timer = timer_start(
            \   200, function('s:update_searchcount'))
function! s:update_searchcount(timer) abort
    if a:timer ==# s:searchcount_timer
        call searchcount(#{
                    \ recompute: 1, maxcount: 0, timeout: 100})
        redrawstatus
    endif
endfunction
